﻿using IOP.SgrA.GLSL;
using IOP.SgrA.SilkNet.Vulkan;
using IOP.SgrA.SilkNet.Vulkan.Scripted;
using Silk.NET.Vulkan;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace VkSample113
{
    [ShaderVersion("460")]
    [GLSLExtension("GL_ARB_separate_shader_objects : enable")]
    [GLSLExtension("GL_ARB_shading_language_420pack : enable")]
    public partial class TreeVert : GLSLVert
    {
        [PushConstant(64, 0)]
        public ConstantVals myConstantVals { get; set; }
        [UniformBuffer(0, 0, DescriptorSetTarget.RenderObject)]
        public TreeVals myBufferVals {  get; set; }
        [VertInput(0, Format.R32G32B32Sfloat)]
        public vec3 pos { get; set; }
        [VertInput(1, Format.R32G32Sfloat)]
        public vec2 inTexCoor { get; set; }

        [ShaderOutput(0)]
        public vec2 outTexCoor { get; set; }

        public override void main()
        {
            float current_radian = pos.y / myBufferVals.bend_R; //计算当前的弧度(θ)
            float pianDistance = myBufferVals.bend_R - myBufferVals.bend_R * cos(current_radian);//偏移距离
            float result_X = pos.x + pianDistance * sin(radians(myBufferVals.direction_degree));//偏移后的X 坐标
            float result_Y = myBufferVals.bend_R * sin(current_radian); //偏移后的Y 坐标
            float result_Z = pos.z + pianDistance * cos(radians(myBufferVals.direction_degree));//偏移后的Z 坐标
            vec4 tPostion = new vec4(result_X, result_Y, result_Z, 1.0f); //得到最后的坐标
            outTexCoor = inTexCoor; //传输到片元着色器的纹理坐标
            gl_Position = myConstantVals.mvp * tPostion; //计算顶点最终位置
        }
    }

    public struct TreeVals
    {
        public float bend_R;
        public float direction_degree;
    }
}
